package DBPack;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Tariff {
	private int tariff_id;
	private String tariff_name;
	
	public Tariff(){	
		super();
	}
	
	public void cloneTariff(Tariff trf){
		this.tariff_id = trf.tariff_id;
		this.tariff_name = trf.tariff_name;
	}

	public int getTariff_id() {
		return tariff_id;
	}

	public void setTariff_id(int tariff_id) {
		this.tariff_id = tariff_id;
	}

	public String getTariff_name() {
		return tariff_name;
	}

	public void setTariff_name(String tariff_name) {
		this.tariff_name = tariff_name;
	}
	
	public boolean insertTariff(){
		try{
			String query = "INSERT INTO `transportation`.`tariff` (`tariff_id`, `tariff_name`) " +
					"VALUES('"+this.tariff_id+"','"+this.tariff_name+"')";
			PreparedStatement ps=(PreparedStatement) DBStatement.getMainConnection().prepareStatement(query);
			ps.executeUpdate();
		} catch(SQLException e) {
			System.err.println("SQLException: "+e.getMessage());
			return false;
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println(e.getMessage());
			return false;
		}
		return true;
	}
}
